package pl.edu.mimuw.irs.core.model.design.net;

import pl.edu.mimuw.irs.core.global.IDManager;
import pl.edu.mimuw.irs.core.model.design.exception.InternalDesignException;
import pl.edu.mimuw.irs.core.model.design.exception.InternalDesignException.DesignCause;
import pl.edu.mimuw.irs.core.model.design.net.refinement.IRSActivityChildren;
import pl.edu.mimuw.irs.core.util.Position;

/**
 * @author Jakub Rauch
 * Created on: 2009-05-07
 */
public class IRSActivity extends IRSTransition {
	
	private static final long serialVersionUID = 6246018324000613033L;
	
	// *** Constructors
	
	public IRSActivity(IDManager idManager, String id, Position position) {
		super(idManager, id, position);
	}

	public IRSActivity(IDManager idManager, Position position) {
		super(idManager, position);
	}
	
	public IRSActivity(IDManager idManager) {
		super(idManager);
	}
	
	/** Copying constructor. */
	public IRSActivity(IRSActivity activity) {
		super(activity);
	}
	
	/** Constructor for changing transition into activity. */
	public IRSActivity(IRSTransition transition) {
		super(transition);
	}
	
	// *** Methods

	public IRSRequirement getRequirement() {
		try {
			return ((IRSActivityChildren)getParent().getChildren()).getRequirement();
		} catch (Exception ex) {
			throw new InternalDesignException(DesignCause.CO_REQUIREMENT_NOT_FOUND, ex, this);
		}
	}
	
	public int getTimeUnits() {
		return getRequirement().getTimeUnits();
	}
	
	public double getDeviation() {
		return getRequirement().getDeviation();
	}
	
//	@Override
//	public void detach() {
//		if (getNet() != null) {
//			IRSWorkflow workflow = Converter.asIRSWorkflow(getNet());
//			workflow.getActivities().remove(this);
//			workflow.getRequirements().remove(getRequirement());
//		}
//		super.detach();
//	}
}
